package exam.Tencent4_4;

import java.util.Scanner;

//腾讯4.4第五题
public class test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        int[] dp = new int[2005];
        int[] temp = new int[2005];
        for (int q = 0; q < T; q++) {
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            int[] w = new int[n + 1];
            for (int j = 0; j < n; j++) {
                w[j] = scanner.nextInt();
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (j == 0 || temp[j] != 0) {
                        dp[(j + w[i]) % m] = temp[j] + 1;
                    }
                    for (j = 0; j < m; j++) {
                        temp[j] = Math.min(temp[j], dp[j]);
                    }
                }
            }
            if(dp[0]==0){
                System.out.println(-1);
            }else{
                System.out.println(dp[0]);
            }
        }
    }
}
